package com.baizhi.cmfz.controller;

import com.baizhi.cmfz.entity.CmfzLog;
import com.baizhi.cmfz.entity.CmfzRole;
import com.baizhi.cmfz.service.CmfzLogService;
import com.baizhi.cmfz.service.CmfzRoleService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/role")
public class CmfzRoleController {

    @Autowired
    private CmfzRoleService crs;

    /**
     * 分页查询所有
     */
    @RequestMapping("/selectAllPage")
    @ResponseBody
    public Map selectAllByPage(@RequestParam(value = "page",defaultValue = "1") Integer page,
                               @RequestParam(value = "limit",defaultValue = "5") Integer limit){
        Page<CmfzRole> pi = crs.selectAllByPage(page, limit);
        //改好layui需要的json格式
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",pi.getTotal());
        map.put("data",pi.getRecords());
        return map;
    }

    /**
     * 查看所有角色
     */
    @RequestMapping("/selectAll")
    @ResponseBody
    public List<CmfzRole> selectAll(){
        return crs.selectAll();
    }
}
